package com.boboPlanet.comm.component;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @Description: TODO 单机ES配置，集群在配置文件中配置地址
 * @Author: mis_wu
 * @Date: 2023/6/21
 * @Company planet
 **/
@Configuration
public class ElasticsearchConfig extends AbstractElasticsearchConfiguration {

    private final List<String> esAddr = Collections.singletonList("127.0.0.1:9200");

    @Override
    @Bean
    public RestHighLevelClient elasticsearchClient() {
        final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo(esAddr.get(0))
                .build();

        return RestClients.create(clientConfiguration).rest();
    }
}
